//
//  CMDBQNController.swift
//  CMDB
//
//  Created by 王磊 on 17/4/6.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit


typealias CMDBQNTokenHandler = (token: String) -> ()

typealias CMDBQNUploadProgressHandler = (percent: Float,uploadStatus: CMDBUploadStatus) -> ()

typealias CMDBQNuUploadHandler = (qnUrl: String) -> ()

public let CMDB_QN_Domain_String: String = "http://on77tknxg.bkt.clouddn.com/"


// MARK: 毫秒时间戳
extension NSDate {
    
    static func timeStamp_ms_cmdb() -> Int {
        
        return Int(NSDate().timeIntervalSince1970) * 1000
    }
}
// 通过图片 获取路径
extension UIImage {
    
    static func qn_GetImagePath(image: UIImage?,imageName: String?) -> String {
        guard let _ = image else {
            return ""
        }
        let data = UIImageJPEGRepresentation(image!, 0.1)
        
        let documentsPath = (NSHomeDirectory() as NSString).stringByAppendingPathComponent("Documents")
        
        let fm = NSFileManager.defaultManager()
        
        try! fm.createDirectoryAtPath(documentsPath, withIntermediateDirectories:  true, attributes: nil)
        
        let imagePath = "/\(imageName!)"
        
        fm.createFileAtPath("\(documentsPath)\(imagePath)", contents: data, attributes: nil)
        
        return "\(documentsPath)\(imagePath)"
    }
    
    class func qn_RemoveImageAtPath(imageName: String) {
        let documentsPath = (NSHomeDirectory() as NSString).stringByAppendingPathComponent("Documents")
        
        let fm = NSFileManager.defaultManager()
        
        let filePath = "\(documentsPath)/\(imageName)"
        
        do {
            try fm.removeItemAtPath(filePath)
            
        } catch {
            
        }
        
        
    }
}